/**
 * Storage二次封装
 *
 */
import appConfig from "@/config/index";

export default {
  setItem(key: string, val: any): void {
    const storage: StorageItem = this.getStroage();
    storage[key] = val;
    window.localStorage.setItem(appConfig.namespace, JSON.stringify(storage));
  },
  getItem(key: string): any {
    return this.getStroage()[key];
  },
  getStroage(): StorageItem {
    return JSON.parse(window.localStorage.getItem(appConfig.namespace) || "{}");
  },

  clearItem(key: string): void {
    const storage = this.getStroage();
    delete storage[key];
    window.localStorage.setItem(appConfig.namespace, JSON.stringify(storage));
  },
  clearAll(): void {
    window.localStorage.clear();
  },
};

interface StorageItem {
  [key: string]: any; // 或者指定具体的类型，如 string | number | boolean
}
